package com.share.user.fallback;

import com.share.common.core.domain.Result;
import com.share.user.api.RemoteH5UserService;
import com.share.user.domain.UpdateUserLogin;
import com.share.user.domain.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 小程序端用户服务降级处理
 *
 * @author share
 */
@Slf4j
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteH5UserService> {

    @Override
    public RemoteH5UserService create(Throwable throwable) {

        log.error("用户服务调用失败:{}", throwable.getMessage());

        return new RemoteH5UserService() {

            @Override
            public Result<UserInfo> wxLogin(String code) {
                log.error("微信用户登录失败");
                return Result.fail("微信用户登录失败"+throwable.getMessage());
            }

            @Override
            public Result<Boolean> updateUserLogin(UpdateUserLogin updateUserLogin) {
                return Result.fail("更新用户登录失败:" + throwable.getMessage());
            }

            @Override
            public Result<UserInfo> getUserInfo(Long id) {
                return Result.fail("查询用户信息失败:" + throwable.getMessage());
            }
        };

    }
}
